<template>
  <div>
    <h3>{{ question.text }}</h3>
    <a-checkbox-group >
      <a-checkbox
          v-for="option in question.options"
          :key="option.value"
          :value="option.value"
          disabled
      >{{ option.text }}
        <span style="color: red">{{getExclusiveInfo(option.value)}}</span>
      </a-checkbox>
    </a-checkbox-group>
  </div>
</template>

<script setup>
  import {defineProps} from 'vue';
  import {useQuestions} from "@/utils/paper.js";
  const { getQuestionById } = useQuestions()
  const props = defineProps({
    questionId:{
      type: String
    }
  });
  const questionId=props.questionId;// 该题的id
  const question=getQuestionById(questionId);// 根据Id查询题目
  const getExclusiveInfo=(choiceValue)=>{
    // 获取 exclusive 数组
    const exclusiveArray = question.ruleLogic?.exclusive || [];

    // 遍历 exclusive 数组，检查每个对象的 value 是否与 choiceValue 匹配
    for (let logic of exclusiveArray) {
      if (logic.value === choiceValue) {
        // 如果匹配，返回排他项的字符串
        return logic.exclusive.length===0?``:`排他项[${logic.exclusive.join(",")}]`;
      }
    }
    // 如果没有匹配的，返回空字符串
    return '';
  }


</script>
